﻿
#region Usings

using PolyGameEngine.GamePieces;
using PolyGameEngine.GamePieces.Common;
using PolyGameEngine.Tools;

using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;

using Microsoft.Xna.Framework;

#endregion

namespace PolyMorph.CustomGamePieces
{
    public class MaterialTile : Tile
    {


        public MaterialTile(PhysicsGame PhysicsGame, World World, Material Material, Vector2 Position, float Rotation, int saveLineIndex, string GPID)
            : base(PhysicsGame, World, Material, Position, Rotation, 50, 50, 1, saveLineIndex, GPID)
        {

        }

        public override bool HandleDefaultCollision(Fixture ThisFixture, Fixture OtherFixture, Contact Contact)
        {
            if (OtherFixture.UserData != null &&
                OtherFixture.UserData.GetType().IsSubclassOf(typeof(Unit)) &&
                !ReferenceEquals(((Unit)(OtherFixture.UserData)).material, material))
            {
                ((Unit)(OtherFixture.UserData)).ChangeMaterial(material);
                ((Unit)(OtherFixture.UserData)).isNormalJumpUp = true;
            }

            return base.HandleDefaultCollision(ThisFixture, OtherFixture, Contact);

        }

        public override void HandleDefaultAfterCollision(Fixture ThisFixture, Fixture OtherFixture)
        {
            base.HandleDefaultAfterCollision(ThisFixture, OtherFixture);
        }
    }
}
